<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2022-04-19 17:14:46
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-10 17:24:50
-->
<template>
  <div>
    <el-dialog
      title="权限编辑"
      :visible.sync="dialog.editTeamShow"
      width="30%"
      @close="teamClose"
      :modal='false'
    >
      <el-form :model="editForm" ref="editForm" label-position="top">
        <el-form-item label="权限">
          <el-radio v-model="editForm.readonly" label="1">只读</el-radio>
          <el-radio v-model="editForm.readonly" label="0">读写</el-radio>
        </el-form-item>
        <el-form-item label="有效时间">
          <el-select v-model="editForm.effValue" @change="timeChange">
            <el-option
              v-for="item in effOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-date-picker
            v-model="editForm.expire"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-if="timeShow"
            style="margin-left: 20px"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="dialog.editTeamShow = false">取消</el-button>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { updateTeam } from "@/api/team";
export default {
  props: {
    dialog: {
      type: Object,
      required: true,
    },
    teamForm: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      timeShow: this.teamForm.expire == null ? false : true,
      editForm: {
        id: this.teamForm.id,
        readonly: this.teamForm.readonly + "",
        effValue: this.teamForm.expire == null ? 1 : 2,
        expire: this.teamForm.expire,
      },
      effOptions: [
        {
          value: 1,
          label: "不限",
        },
        {
          value: 2,
          label: "截止到",
        },
      ],
    };
  },
  methods: {
    timeChange(val) {
      if (val == 1) {
        this.timeShow = false;
      } else if (val == 2) {
        this.timeShow = true;
      }
    },
    // 关闭
    teamClose() {
      this.dialog.editTeamShowEject = false;
    },
    // 保存
    onSubmit() {
      console.log(this.editForm);
      updateTeam(this.editForm).then((res) => {
        this.$message.success(res.msg);
        this.$parent.getTeamList();
        this.dialog.editTeamShow = false;
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>